package com.aruba.room;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

/**
 * Created by aruba on 2021/9/12.
 */
@Dao
public interface UserDao {
    //查询
    @Query("SELECT * FROM user")
    LiveData<List<User>> getUsers();

    //根据id查询
    @Query("SELECT * FROM user WHERE id = :id")
    User getUserById(int id);

    //插入一条数据
    @Insert
    void insertUser(User user);

    //删除一条数据
    @Delete
    void deleteUser(User user);

    //删除所有数据
    @Query("DELETE  FROM user")
    void deleteAllUser();

    //更新一条数据
    @Update
    void updateUser(User user);
}
